/* 
 * Copyright (C) 2007 Eskil Bylund
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

using System;

namespace DCSharp.Backend.Objects
{
	public class RequestEventArgs : EventArgs
	{
		private Request request;

		public RequestEventArgs(Request request)
		{
			this.request = request;
		}

		public Request Request
		{
			get { return request; }
		}
	}

	public enum RequestType
	{
		File,
		List,
		HashTree
	}

	public abstract class Request
	{
		private RequestType type;

		protected Request(RequestType type)
		{
			this.type = type;
		}

		public RequestType Type
		{
			get { return type; }
		}
	}

	public class FileRequest : Request
	{
		private string path;
		private string tth;
		private long start;
		private long? count;

		public FileRequest(string path, string tth, long start, long? count) :
			base(RequestType.File)
		{
			if (path == null && tth == null)
			{
				throw new ArgumentNullException("path and tth");
			}
			this.path = path;
			this.tth = tth;
			this.start = start;
			this.count = count;
		}

		public string Path
		{
			get { return path; }
		}

		public string TTH
		{
			get { return tth; }
		}

		public long Start
		{
			get { return start; }
		}

		public long? Count
		{
			get { return count; }
		}

		public override string ToString()
		{
			return String.Format("File: {0} ({1}, {2})",
				tth ?? path, start, count);
		}
	}

	public class HashTreeRequest : Request
	{
		private string tth;

		public HashTreeRequest(string tth) : base(RequestType.HashTree)
		{
			if (tth == null)
			{
				throw new ArgumentNullException("tth");
			}
			this.tth = tth;
		}

		public string TTH
		{
			get { return tth; }
		}

		public override string ToString()
		{
			return "Hash Tree: " + tth;
		}
	}

	public class ListRequest : Request
	{
		private bool compressed;

		public ListRequest(bool compressed) : base(RequestType.List)
		{
			this.compressed = compressed;
		}

		public bool Compressed
		{
			get { return compressed; }
		}

		public override string ToString()
		{
			return "File List";
		}
	}
}
